package com.jwater.core.common.param;

import java.io.IOException;
import java.lang.reflect.Type;

import jwater.com.alibaba.fastjson.JSON;
import jwater.com.alibaba.fastjson.serializer.JSONSerializer;
import jwater.com.alibaba.fastjson.serializer.ObjectSerializer;
import jwater.com.alibaba.fastjson.serializer.SerializeConfig;

/**
 * @description: ParamMap转化为json支持
 * @author: jnner
 * @createDate: 2021/2/5
 * @version: 1.0
 */
public class ParamMapCodec implements ObjectSerializer {
    public final static ParamMapCodec instance = new ParamMapCodec();

    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
            throws IOException {
        ParamMapImpl paramMap = (ParamMapImpl) object;
        SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.put(ParamMapImpl.class, ParamMapCodec.instance);
        serializer.getWriter().write(JSON.toJSONString(paramMap.getParams(), serializeConfig));
    }
}
